package com.education.welco.service.impl;

import com.education.welco.mapper.SysSensitiveWordMapper;
import com.education.welco.pojo.SysSensitiveWord;
import com.education.welco.service.ISysSensitiveWordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SysSensitiveWordServiceImpl implements ISysSensitiveWordService {
    @Autowired
    private SysSensitiveWordMapper sysSensitiveWordMapper;
    @Override
    public int addSensitiveWord(SysSensitiveWord sysSensitiveWord) {
        try{
            return sysSensitiveWordMapper.insertSelective(sysSensitiveWord);
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public int updateSensitiveWord(SysSensitiveWord sysSensitiveWord) {
        return sysSensitiveWordMapper.updateByPrimaryKeySelective(sysSensitiveWord);
    }

    @Override
    public int delSensitiveWord(SysSensitiveWord sysSensitiveWord) {
        return sysSensitiveWordMapper.deleteByPrimaryKey(sysSensitiveWord.getId());
    }

    @Override
    public PageInfo getSysSensitiveWordList(SysSensitiveWord sysSensitiveWord) {
        Integer pageSize = sysSensitiveWord.getPageSize();
        Integer pageNum = sysSensitiveWord.getPageNum();
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
//        List list = sysSensitiveWordMapper.getSysSensitiveWordList(sysSensitiveWord);
//        PageInfo pageInfo = new PageInfo<>(list);
//        PageInfo<SysSensitiveWord> pageInfo = new PageInfo<>(list);
        List<SysSensitiveWord> sysCatalogMenus = sysSensitiveWordMapper.getSysSensitiveWordList(sysSensitiveWord);
        return new PageInfo<>(sysCatalogMenus);
    }

    @Override
    public List<SysSensitiveWord> getSysSensitiveWordAllList() {
        return sysSensitiveWordMapper.getSysSensitiveWordList(new SysSensitiveWord());
    }

}
